package jiang.web.controller.dataCollection;

import java.io.File;

import javax.servlet.http.HttpSession;

import jiang.app.entity.Candidate;
import jiang.app.service.RecommendService;
import jiang.commom.DateHelper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartFile;

@Controller
public class RecommendController {
	@Autowired
	RecommendService recommendService;

	@RequestMapping(value = "/manage/dataCollection/recommend", method = RequestMethod.GET)
	public String recommend() {
		return "dataCollection/recommend/index";
	}

	@RequestMapping(value = "/manage/dataCollection/recommend", method = RequestMethod.POST)
	public String recommend2(Candidate c, MultipartFile file, HttpSession s,
			Model m) {
		String savePath = s.getServletContext().getRealPath(
				"jsp/dataCollection/resume")
				+ File.separator
				+ c.getName()
				+ "-"
				+ DateHelper.getCurrentDate()
				+ "-"
				+ file.getOriginalFilename();
		c.setResumePath(savePath);
		c.setRegisterTime(DateHelper.getCurrentDate());
		boolean success = recommendService.saveCandidate(c);
		boolean success2 = recommendService.saveResume(file, savePath);
		if (success && success2) {
			m.addAttribute("tip", "提交成功");
		} else {
			m.addAttribute("tip", "提交失败");
		}
		return "dataCollection/recommend/result";
	}
}
